﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;

namespace Smith.ImageConverter
{
    public class BaseResize : IResize
    {
        public ResampleOption ResampleMode
        {
            get;
            set;
        }

        public virtual Bitmap Resize(Bitmap image)
        {
            Size newSize = GetNewSize(image.Width, image.Height);
            Bitmap result = new Bitmap(newSize.Width, newSize.Height);
            using (Graphics g = Graphics.FromImage(result))
            {
                g.InterpolationMode = (InterpolationMode)ResampleMode;
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                g.DrawImage(image, 0, 0, newSize.Width, newSize.Height);
                return result;
            }
        }

        protected virtual Size GetNewSize(int width, int height)
        {
            return new Size(width, height);
        }
    }
}
